﻿using System.Collections.Generic;
using Missbot.Service;

namespace Missbot.AIModule.Record
{
    public class Saying : DbBaseEntity
    {
        public string Cartoon { get; init; }
        public string Charactor { get; init; }
        public string FromGroupID { get; init; }
        public string FromUserID { get; set; }
        public string Content { get; init; }
    }

    public static class SayingDA
    {
        public static int Delete(string groupID, string key)
        {
            return (int)MongoService<Saying>.DeleteMany(s => s.FromGroupID == groupID &&
                                                             (s.Content.Contains(key) ||
                                                              s.Charactor.Contains(key) ||
                                                              s.Cartoon.Contains(key)));
        }

        public static void Insert(this Saying entity)
        {
            MongoService<Saying>.Insert(entity);
        }

        public static IEnumerable<Saying> Get(string groupID)
        {
            return MongoService<Saying>.Get(p => p.FromGroupID == groupID);
        }
    }
}